﻿@using Microsoft.Web.Helpers
@using VideoSeller.Business.Data.Enums
@model OnlineViewModel

<script type="text/javascript">

    function number_format(_number, _cfg) {
        function obj_merge(obj_first, obj_second) {
            var obj_return = {};
            for (key in obj_first) {
                if (typeof obj_second[key] !== 'undefined') obj_return[key] = obj_second[key];
                else obj_return[key] = obj_first[key];
            }
            return obj_return;
        }
        function thousands_sep(_num, _sep) {
            if (_num.length <= 3) return _num;
            var _count = _num.length;
            var _num_parser = '';
            var _count_digits = 0;
            for (var _p = (_count - 1) ; _p >= 0; _p--) {
                var _num_digit = _num.substr(_p, 1);
                if (_count_digits % 3 == 0 && _count_digits != 0 && !isNaN(parseFloat(_num_digit))) _num_parser = _sep + _num_parser;
                _num_parser = _num_digit + _num_parser;
                _count_digits++;
            }
            return _num_parser;
        }
        if (typeof _number !== 'number') {
            _number = parseFloat(_number);
            if (isNaN(_number)) return false;
        }
        var _cfg_default = { before: '', after: '', decimals: 2, dec_point: '.', thousands_sep: ',' };
        if (_cfg && typeof _cfg === 'object') {
            _cfg = obj_merge(_cfg_default, _cfg);
        }
        else _cfg = _cfg_default;
        _number = _number.toFixed(_cfg.decimals);
        if (_number.indexOf('.') != -1) {
            var _number_arr = _number.split('.');
            var _number = thousands_sep(_number_arr[0], _cfg.thousands_sep) + _cfg.dec_point + _number_arr[1];
        }
        else var _number = thousands_sep(_number, _cfg.thousands_sep);
        return _cfg.before + _number + _cfg.after;
    }


	function saveStepData() {
		//window.OnlineContent.VideoContentType =		$("#ddlContentType").val();
		if (window.OnlineContent.VideoContentType == "@VideoContentType.Free.ToString()") {
		    if ($("#freePasswordCheckbox")[0].checked) {
		        window.OnlineContent.Password = $("#PasswordFree").val();
		    } else { window.OnlineContent.Password = '';}
		} else if (window.OnlineContent.VideoContentType == "@VideoContentType.Paid.ToString()") {
			if ($("#paidPasswordCheckbox")[0].checked) {
				window.OnlineContent.Password = $("#PasswordPaid").val();
			} else { window.OnlineContent.Password = ''; }

			window.OnlineContent.TeamDocumentsListHtmlPaidGroups = "";
			window.OnlineContent.TeamDocumentsUrlsPaidGroups = "";
			window.OnlineContent.TeamDocumentsNamesPaidGroups = "";
		} else if (window.OnlineContent.VideoContentType == "@VideoContentType.PaidGroups.ToString()") {
		    if ($("#paidGroupsPriceCheckbox")[0].checked) {
		        window.OnlineContent.Price = $("#PricePaidGroups").val();
		    } else { window.OnlineContent.Price = '0' }

			window.OnlineContent.Password = $("#PasswordPaidGroups").val();
			window.OnlineContent.TeamCount = $("#TeamCountPaidGroups").val();
			window.OnlineContent.TeamDocumentsListHtmlPaid = "";
			window.OnlineContent.TeamDocumentsUrlsPaid = "";
			window.OnlineContent.TeamDocumentsNamesPaid = "";
			//window.OnlineContent.RemoveAds = $("#paidGroupsRemoveAds").is(":checked");
		}
		$("input[name='Category']");
		window.OnlineContent.AutoHistory = $("#setAutoHistory")[0].checked;
	}
    function check_paid() {
        
    	var ret =($("#MaxPriceConferenceVSMOverflow").is(":hidden") && $("#MaxPriceMyVSMOverflow").is(":hidden"));
    	return ret;
    }
	@*function validateCaptcha() {
		var retRes = false;

		if (Recaptcha.get_response() == "") {
			$(".validation").empty();
			$(".validation").append("<label class=\"error\">" + "@Html.GetGlobalResource("OnlineWizard", "CaptchaRequired")" + "</label>");
			$(".validation").append("<br/>");
			return false;
		}

		$.ajax({
			type: "POST",
			url: window.MAIN_WEB_PATH + "Ajax/ValidateReCaptcha",
			dataType: "json",
			async: false,
			data: {
				challenge: Recaptcha.get_challenge(),
				response: Recaptcha.get_response(),
			},
			success: function (data, textStatus, jqXHR) {
				var result = data.toString().split("\n");
				if (result[0] == "true") {
					retRes = true;
				} else {
					Recaptcha.reload();
					$(".validation").empty();
					$(".validation").append("<label class=\"error\">" + "@Html.GetGlobalResource("OnlineWizard", "CaptchaInvalid")" + "</label>");
					$(".validation").append("<br/>");
					retRes = false;
				}
			}
		});
		return retRes;
	}*@

	function loadStepData() {
		$("#wizard form").validate({
			rules: {
				PasswordFree: { required: "#freePasswordCheckbox:checked" },
				PriceFree: { required: "#freePriceCheckbox:checked", number: true },

				PasswordPaid: { required: "#paidPasswordCheckbox:checked" },
				PricePaid: { required: "#paidPriceCheckbox:checked", number: true }
			},
			messages: {
				PasswordFree: { required: "@Html.GetGlobalResource("OnlineWizard", "PasswordRequired")" },
			    PriceFree: { required: "@Html.GetGlobalResource("OnlineWizard", "PriceRequired")", number: "@Html.GetGlobalResource("OnlineWizard", "NumbersAllowed")" },

				PasswordPaid: { required: "@Html.GetGlobalResource("OnlineWizard", "PasswordRequired")" },
			    PricePaid: { required: "@Html.GetGlobalResource("OnlineWizard", "PriceRequired")", number: "@Html.GetGlobalResource("OnlineWizard", "NumbersAllowed")" }
			},
			errorPlacement: function (error, element) {
				$(".validation").append(error);
				$(".validation").append("<br/>");
			}
		});

@*		jQuery.validator.addMethod("payment-required", function(value, element) {
			if (parseInt($("#removeAdsPrice").text()) > parseInt("@Model.CurrentMembershipUser.Client.Finance.Total") &&
				$("#paidGroupsRemoveAds").is(":checked")) {
				return false;
			}
			return true;
		}, "@Html.GetGlobalResource("OnlineWizard", "NotEnoughMoney")");
*@



		var uploaderPaid = new plupload.Uploader({
			runtimes: 'gears,html5,flash,silverlight,browserplus',
			file_data_name: 'docs',
			browse_button: 'uploadFileButtonPaid',
			container: 'files-container-paid',
			max_file_size: '100mb',
			multi_selection: true,
			url: '@Url.Action("UploadOnlineTeamDocs", "Ajax")',
			flash_swf_url: '@Url.Content("~/Content/flash/plupload.flash.swf")',
			silverlight_xap_url: '@Url.Content("~/Content/flash/plupload.silverlight.*xap")',
			filters: [{ title: '@Html.GetGlobalResource("OnlineWizard", "ImageFiles")', extensions: "*" }],
			init: {
				UploadProgress: function(up, file) {
					$("#percentagePaid")[0].innerHTML = '<span>' + file.percent + "%</span>";
				},
				FilesAdded: function(up, files) {
					up.start();
				},
				FileUploaded: function(up, file, info) {
					if (info.response) {
						$("#docsListPaid").append("<li>" + file.name + "</li>");
						window.OnlineContent.TeamDocumentsListHtmlPaid = $("#docsListPaid").html();
						window.OnlineContent.TeamDocumentsUrlsPaid += info.response + ";";
						window.OnlineContent.TeamDocumentsNamesPaid += file.name + ";";
					}
				}
			}
		});
		uploaderPaid.init();

		$("#freePasswordCheckbox").change(function () {
			if ($(this).is(":checked")) {
				$("#PasswordFree").show();
			} else {
				$("#PasswordFree").hide();
			}
		});
		$("#paidPasswordCheckbox").change(function () {
			if ($(this).is(":checked")) {
				$("#PasswordPaid").show();
			} else {
				$("#PasswordPaid").hide();
			}
		});

		$("#PasswordFree").hide();
		$("#PasswordPaid").hide();

		if (window.OnlineContent.VideoContentType && window.OnlineContent.VideoContentType != "") {

		    if (window.OnlineContent.VideoContentType == "@VideoContentType.Free.ToString()") {
				if (window.OnlineContent.Password != "") {
					$("#PasswordFree").val(window.OnlineContent.Password);
					$("#PasswordFree").show();
					$("#freePasswordCheckbox").attr("checked", "checked");
					
				}
				if (window.OnlineContent.AutoHistory) {
				    $("#setAutoHistory").attr("checked", "checked");
				}

			} else if (window.OnlineContent.VideoContentType == "@VideoContentType.Paid.ToString()") {
				if (window.OnlineContent.Password != "") {
					$("#PasswordPaid").val(window.OnlineContent.Password);
					$("#PasswordPaid").show();
					$("#paidPasswordCheckbox").attr("checked", "checked");
				}

				if (window.OnlineContent.AutoHistory) {
				    $("#setAutoHistory").attr("checked", "checked");
				}

				$("#docsListPaid").html(window.OnlineContent.TeamDocumentsListHtmlPaid);
			}
		}


        /*Блин, ну не было времени сделать правильно :) Не фанат я Javascript (HPN)*/
	    //var objSel = document.getElementById("ddlContentType");
	    //switch (window.OnlineContent.VideoContentType) {
	    //    case 'Free':
	    //        objSel.selectedIndex = 0;
	    //        break;
	    //    case 'Paid':
	    //        objSel.selectedIndex = 1;
	    //        break;
	    //    case 'PaidGroups':
	    //        objSel.selectedIndex = 2;
	    //        break;
		//}
		if (window.OnlineContent.VideoContentType  == "Free")
			$("#broadcastingTitle").text('@Html.GetGlobalResource("OnlineWizard", "VideoContentTypeFree")');
		if (window.OnlineContent.VideoContentType == "Paid")
			$("#broadcastingTitle").text('@Html.GetGlobalResource("OnlineWizard", "VideoContentTypePaid")');

		switchVideoContentType();
	}

	function switchVideoContentType() {
		$("#freeContent").hide();
		$("#paidContent").hide();
		$("#paidContentFiles").hide();
		$("#paidGroupsContent").hide();
		$("#setAutoHistory").hide();
		$("#setAutoHistoryLabel").hide();
		$("#group_count").hide();

		var selected = window.OnlineContent.VideoContentType;

		if (selected == "@VideoContentType.Free.ToString()" || selected == "@VideoContentType.Paid.ToString()") {
			$("#setAutoHistory").show();
			$("#setAutoHistoryLabel").show();
		}

		if (selected == "@VideoContentType.Free.ToString()") {
			$("#freeContent").show();
		}
		else if (selected == "@VideoContentType.Paid.ToString()") {
		    $("#paidContent").show();
		    $("#paidContentFiles").show();
		}

	}


</script>
<form>
    <div class="steps"><h4>Step 5 of 5</h4></div>
	<h3 id="broadcastingTitle" name="broadcastingTitle"></h3>
	<div class="validation"></div>
	<label> </label>
    
	<div class="type-content-choose">
		<div id="freeContent">
			<input id="freePasswordCheckbox" type="checkbox" />&nbsp;
            <label for="freePasswordCheckbox">@Html.GetGlobalResource("OnlineWizard", "PasswordFree")</label>
            &nbsp;@Html.Password("PasswordFree")<br />
		</div>
	</div>
	<div class="type-content-choose">
		<div id="paidContent">
			<input id="paidPasswordCheckbox" type="checkbox" />&nbsp;<label for="paidPasswordCheckbox">@Html.GetGlobalResource("OnlineWizard", "PasswordFree")</label>&nbsp;@Html.Password("PasswordPaid")<br />
		</div>
	</div>
    <div class="type-content-choose">
            <input id="setAutoHistory" type="checkbox" />&nbsp;<label id="setAutoHistoryLabel" for="setAutoHistory">@Html.GetGlobalResource("OnlineWizard", "AutoHistory")</label>
    </div>
    <div class="type-content-choose">
        <div id="paidContentFiles">
            <ul id="docsListPaid"></ul>
            <br />
            <div id="files-container-paid">
                <input id="uploadFileButtonPaid" type="button" value="@Html.GetGlobalResource("OnlineWizard", "UploadDocuments")"/>&nbsp;&nbsp;&nbsp;<b id="percentagePaid"></b>
            </div>
        </div>
    </div>
</form>